#!/bin/sh
#
# Copyright (C) 2000-2022 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# TODO fill desc
#

TestName="migration-job-error-test"
JobName=MigrationJobSave
. scripts/functions


scripts/cleanup
scripts/copy-migration-confs
echo "${cwd}/build" >${cwd}/tmp/file-list

change_jobname NightlySave $JobName
start_test

$bperl -e 'add_attribute("$conf/bacula-dir.conf", "SD Connect Timeout", "1", "Director")'


# Write out bconsole commands
cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@output /dev/null
messages
@$out ${cwd}/tmp/log1.out
label storage=File volume=FileVolume001 Pool=Default
run job=$JobName yes
wait
list jobs
quit
END_OF_DATA

run_bacula

pkill bacula-sd
if [ $? -ne 0 ]; then
    print_debug "ERROR: Failed to kill SD!"
    estat=1
fi

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out ${cwd}/tmp/log2.out
run job=migrate-job yes
wait
list jobs
messages
quit
END_OF_DATA

run_bconsole

grep "Migration Error" $tmp/log2.out > /dev/null
if [ $? -ne 0 ]; then
    print_debug "ERROR: should find Migration Error in $tmp/log2.out"
    estat=1
fi

stop_bacula

end_test
